﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Abonent-Details.aspx.cs" Inherits="Abonent_Details" Title="Untitled Page" %>

<asp:Content ID="AbonentDetails" ContentPlaceHolderID="MainContent" Runat="Server">
    <div id="stats-left">  
        <asp:LinkButton ID="lbtnCard" runat="server" onclick="lbtnCard_Click" 
            ForeColor="Yellow">Карточка абонента   </asp:LinkButton>
        <br/>
        <asp:LinkButton ID="lbtnInbox" runat="server" onclick="lbtnInbox_Click">Входящие сообщения</asp:LinkButton>
        <br/>
        <asp:LinkButton ID="lbtnOutbox" runat="server" onclick="lbtnOutbox_Click">Исходящие сообщения</asp:LinkButton>
                    <asp:Calendar ID="cldrDateStart" runat="server" BackColor="White" 
                        BorderColor="#3366CC" BorderWidth="1px" CellPadding="1" 
                        DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" 
                        ForeColor="#003399" Height="200px" 
                        OnSelectionChanged="cldrDateStart_SelectionChanged" SelectedDate="1998-05-01" 
                        ToolTip="начальная дата" VisibleDate="1998-05-01" 
            Width="220px" Visible="False">
                        <SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                        <SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
                        <WeekendDayStyle BackColor="#CCCCFF" />
                        <TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
                        <OtherMonthDayStyle ForeColor="#999999" />
                        <NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
                        <DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
                        <TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" 
                            Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
                    </asp:Calendar>
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    <div id="stats-right">  
    <asp:Label ID="lbTotal" runat="server" Text="Всего: 0" Visible="False"></asp:Label>
            <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
                <asp:View ID="ViewAbonCard" runat="server">
        <asp:DetailsView ID="dvAbonent" runat="server" 
        CellPadding="4" CellSpacing="1" DataSourceID="dsApAtlas" ForeColor="#333333" 
        Height="100px" Width="700px" Font-Size="Small" AutoGenerateRows="False" 
                        HeaderText="Карточка абонента">
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
        <RowStyle BackColor="#EFF3FB" Width="100px" />
        <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" Width="160px"/>
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"/>
        <EditRowStyle BackColor="#2461BF" Width="200px" />
        <AlternatingRowStyle BackColor="White" />
        <Fields>
            <asp:BoundField DataField="surname" HeaderText="Псевдоним" 
                SortExpression="surname" ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="name" HeaderText="Организация" SortExpression="name" 
                ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="city" HeaderText="Город" SortExpression="city" 
                ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="address_x_121" HeaderText="Сет. адрес" 
                SortExpression="address_x_121" ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="kross" HeaderText="КРОСС" SortExpression="kross" 
                ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="grebenka" HeaderText="Гребенка" 
                SortExpression="grebenka" ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="modem" HeaderText="Модем" SortExpression="modem" 
                ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="telefon" HeaderText="Телефон" 
                SortExpression="telefon" ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="tip_device" HeaderText="Оборудование" 
                SortExpression="tip_device" ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="address" HeaderText="Кросс-панель" 
                SortExpression="address" ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="port" HeaderText="Патч-панель" SortExpression="port" 
                ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="tip" HeaderText="Тип" SortExpression="tip" 
                ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="host" HeaderText="ЭП" SortExpression="host" 
                ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="protocol" HeaderText="Протокол" 
                SortExpression="protocol" ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="UserGroup" HeaderText="Группа" 
                SortExpression="UserGroup" ControlStyle-Width="570px">
            <ControlStyle Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="information" HeaderText="Информация" 
                SortExpression="information" ControlStyle-Width="570px" 
                ControlStyle-Height="80px">
            <ControlStyle Height="80px" Width="570px" />
            </asp:BoundField>
            <asp:BoundField DataField="kod" HeaderText="kod" InsertVisible="False" ReadOnly="True"
                SortExpression="kod" Visible="False" ControlStyle-Width="200px">
            <ControlStyle Width="200px" />
            </asp:BoundField>
            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                        Text="Сохранить"></asp:LinkButton>
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                        Text="Отмена"></asp:LinkButton>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Insert"
                        Text="Добавить"></asp:LinkButton>
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                        Text="Отмена"></asp:LinkButton>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                        Text="Редактировать" ForeColor="black"></asp:LinkButton>
                    <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="New"
                        Text="Добавить" ForeColor="black"></asp:LinkButton>
                    <asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" CommandName="Delete"
                       OnClientClick = "return confirm('Действительно удалить?');" Text="Удалить"  ForeColor="black"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Fields>
    </asp:DetailsView>
                </asp:View>
                <asp:View ID="ViewAbonInbox" runat="server">
                    <asp:GridView ID="gvInbox" runat="server" AllowPaging="True" 
                        AutoGenerateColumns="False" Caption="Входящие сообщения" 
                        CaptionAlign="Left" CellPadding="4" CellSpacing="1" DataSourceID="dsApInbox" 
                        EnableTheming="False" Font-Bold="False" ForeColor="Black" PageSize="30" 
                        AllowSorting="True">
                        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <RowStyle BackColor="#EFF3FB" />
                        <Columns>
                            <asp:BoundField DataField="SendTime" HeaderText="Отправлено" 
                                SortExpression="SendTime" >
                            <ItemStyle HorizontalAlign="Center" />
                            </asp:BoundField>
                            <asp:BoundField DataField="msg_id" HeaderText="Идентификатор" 
                                SortExpression="msg_id" >
                            <ItemStyle HorizontalAlign="Center" />
                            </asp:BoundField>
                            <asp:BoundField DataField="FromName" HeaderText="Откуда" 
                                SortExpression="FromName" />
                            <asp:BoundField DataField="msg_size" HeaderText="Размер (бт)" 
                                SortExpression="msg_size" />
                            <asp:BoundField DataField="MsgType" HeaderText="Категория" 
                                SortExpression="MsgType" />
                            <asp:BoundField DataField="msg_cirkul" HeaderText="Цирк." />
                            <asp:BoundField DataField="InfoCode" HeaderText="Инфо" Visible="False" />
                            <asp:BoundField DataField="AliasName" HeaderText="Алиас" 
                                SortExpression="AliasName" />
                            <asp:BoundField DataField="HostName" HeaderText="Хост" 
                                SortExpression="HostName" />
                            <asp:HyperLinkField HeaderText="Отчет" Text="&gt;&gt;&gt;" DataNavigateUrlFields="msg_id,from_abonent_id,to_abonent_id" 
                DataNavigateUrlFormatString="~\message-details.aspx?id={0}&amp;from={1}&amp;to={2}">
                            <ControlStyle ForeColor="Black" />
                            </asp:HyperLinkField>
                        </Columns>
                        <EditRowStyle BackColor="#2461BF" />
                        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>
               
                </asp:View>
<asp:View ID="ViewAbonOutbox" runat="server">
                    <asp:GridView ID="gvOutbox" runat="server" AllowPaging="True" 
                        AutoGenerateColumns="False" Caption="Исходящие сообщения" 
                        CaptionAlign="Left" CellPadding="4" CellSpacing="1" DataSourceID="dsApOutbox" 
                        EnableTheming="False" Font-Bold="False" ForeColor="Black" PageSize="30" 
                        AllowSorting="True" onsorting="gvOutbox_Sorting">
                        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <RowStyle BackColor="#EFF3FB" />
                        <Columns>
                            <asp:BoundField DataField="SendTime" 
                                HeaderText="Отправлено" SortExpression="SendTime" htmlencode="false">
                            <ItemStyle HorizontalAlign="Center" />
                            </asp:BoundField>
                            <asp:BoundField DataField="msg_id" HeaderText="Идентификатор" 
                                SortExpression="msg_id" >
                            <ItemStyle HorizontalAlign="Center" />
                            </asp:BoundField>
                            <asp:BoundField DataField="ToName" HeaderText="Куда" SortExpression="ToName" />
                            <asp:BoundField DataField="msg_size" HeaderText="Байт" 
                                SortExpression="msg_size" />
                            <asp:BoundField DataField="MsgType" HeaderText="Категория" 
                                SortExpression="MsgType" />
                            <asp:BoundField DataField="msg_cirkul" HeaderText="Цирк." />
                            <asp:BoundField DataField="AliasName" HeaderText="Алиас" 
                                SortExpression="AliasName" />
                            <asp:BoundField DataField="HostName" HeaderText="Хост" 
                                SortExpression="HostName" />
                            <asp:HyperLinkField HeaderText="Отчет" Text="&gt;&gt;&gt;" DataNavigateUrlFields="msg_id,from_abonent_id,to_abonent_id" 
                DataNavigateUrlFormatString="~\message-details.aspx?id={0}&amp;from={1}&amp;to={2}">
                            <ControlStyle ForeColor="Black" />
                            </asp:HyperLinkField>
                        </Columns>
                        <EditRowStyle BackColor="#2461BF" />
                        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>
               
                </asp:View>
            </asp:MultiView>
    </div> 
    
    <asp:SqlDataSource ID="dsApAtlas" runat="server" ConnectionString="Data Source=195.0.0.102;Initial Catalog=atlas;Persist Security Info=True;User ID=atlas;Password=atlas-atlas;Connect Timeout=30"
        SelectCommand="SELECT * FROM [apspdatlas]
WHERE kod = @kod" OnSelected="dsApAtlas_Selected" 
        InsertCommand="INSERT INTO apspdatlas(city, tip_device, address, port, name, tip, host, surname, address_x_121, protocol, UserGroup, kross, grebenka, modem, telefon, information) &#13;&#10;VALUES (@city, @tip_device, @address, @port, @name, @tip, @host, @surname, @address_x_121, @protocol, @UserGroup, @kross, @grebenka, @modem, @telefon, @information) " 
        OnInserted="dsApAtlas_Inserted" 
        
        UpdateCommand="UPDATE apspdatlas &#13;&#10;SET city =@city, tip_device =@tip_device, address =@address, port =@port, name =@name, tip =@tip, host =@host, surname =@surname, address_x_121 =@address_x_121, protocol =@protocol, UserGroup =@UserGroup, kross =@kross, grebenka =@grebenka, modem =@modem, telefon =@telefon, information =@information&#13;&#10;WHERE kod = @kod" DeleteCommand="DELETE FROM apspdatlas 
WHERE kod = @kod" ProviderName="System.Data.SqlClient">
        <DeleteParameters>
            <asp:QueryStringParameter DefaultValue="0" Name="kod" QueryStringField="kod" />
        </DeleteParameters>
        <SelectParameters>
            <asp:QueryStringParameter DefaultValue="0" Name="kod" QueryStringField="kod" />
        </SelectParameters>
        <UpdateParameters>
            <asp:QueryStringParameter Name="kod" QueryStringField="kod" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="dsApOutbox" runat="server" ConnectionString="Data Source=195.0.0.102;Initial Catalog=atlas;User ID=atlas;Password=atlas-atlas;Connect Timeout=60"
        SelectCommand="SELECT 
  md.datetime_in as SendTime, 
  ab.surname as ToName,
  md.msg_size,
  mk.comments as MsgType,
  md.msg_cirkul,
  md.msg_id,
  e.item as InfoCode,
  al.item as AliasName,
  h.item as HostName,
  md.from_abonent_id,
  md.to_abonent_id
FROM mon400_data md
INNER JOIN mon400_hostnames h ON md.hostname_id = h.id
INNER JOIN mon400_abonents ab ON md.to_abonent_id = ab.id
INNER JOIN mon400_aliases al ON md.alias_sender_id = al.id
INNER JOIN mon400_errorcodes e ON md.msg_errorcode_id = e.id
INNER JOIN mon400_msg_categories mk ON md.msg_category = mk.item
WHERE 
  (md.from_abonent_id = @ApCode)
  AND (md.datetime_in BETWEEN @StatDate AND (@StatDate + 1))
  AND ((md.msg_kind = 0) or (md.msg_kind = 2))
  AND (al.item NOT IN (SELECT hst.comments FROM mon400_hostnames hst))

" OnSelected="dsApOutbox_Selected" 
            InsertCommand="INSERT INTO apspdatlas(city, tip_device, address, port, name, tip, host, surname, address_x_121, protocol, UserGroup, kross, grebenka, modem, telefon, information) &#13;&#10;VALUES (@city, @tip_device, @address, @port, @name, @tip, @host, @surname, @address_x_121, @protocol, @UserGroup, @kross, @grebenka, @modem, @telefon, @information) " 
            
        
        
        
        UpdateCommand="UPDATE apspdatlas &#13;&#10;SET city =@city, tip_device =@tip_device, address =@address, port =@port, name =@name, tip =@tip, host =@host, surname =@surname, address_x_121 =@address_x_121, protocol =@protocol, UserGroup =@UserGroup, kross =@kross, grebenka =@grebenka, modem =@modem, telefon =@telefon, information =@information&#13;&#10;WHERE kod = @kod">
        <SelectParameters>
            <asp:Parameter DefaultValue="0" Name="StatDate" Type="DateTime" />
            <asp:Parameter DefaultValue="0" Name="ApCode" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:QueryStringParameter Name="kod" QueryStringField="kod" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="dsApInbox" runat="server" ConnectionString="Data Source=195.0.0.102;Initial Catalog=atlas;User ID=atlas;Password=atlas-atlas;Connect Timeout=60"
        SelectCommand="SELECT 
  md.datetime_in as SendTime, 
  ab.surname as FromName,
  md.msg_size,
  mk.comments as MsgType,
  md.msg_cirkul,
  md.msg_id,
  e.item as InfoCode,
  al.item as AliasName,
  h.item as HostName,
  md.from_abonent_id,
  md.to_abonent_id
FROM mon400_data md
INNER JOIN mon400_hostnames h ON md.hostname_id = h.id
INNER JOIN mon400_abonents ab ON md.from_abonent_id = ab.id
INNER JOIN mon400_aliases al ON md.alias_sender_id = al.id
INNER JOIN mon400_errorcodes e ON md.msg_errorcode_id = e.id
INNER JOIN mon400_msg_categories mk ON md.msg_category = mk.item
WHERE 
  (md.to_abonent_id = @ApCode)
  AND (md.datetime_in BETWEEN @StatDate AND (@StatDate + 1))
  AND (md.msg_kind = 0)
  AND (al.item NOT IN (SELECT hst.comments FROM mon400_hostnames hst))" OnSelected="dsApInbox_Selected" 
            InsertCommand="INSERT INTO apspdatlas(city, tip_device, address, port, name, tip, host, surname, address_x_121, protocol, UserGroup, kross, grebenka, modem, telefon, information) &#13;&#10;VALUES (@city, @tip_device, @address, @port, @name, @tip, @host, @surname, @address_x_121, @protocol, @UserGroup, @kross, @grebenka, @modem, @telefon, @information) " 
            
        
        
        
        UpdateCommand="UPDATE apspdatlas &#13;&#10;SET city =@city, tip_device =@tip_device, address =@address, port =@port, name =@name, tip =@tip, host =@host, surname =@surname, address_x_121 =@address_x_121, protocol =@protocol, UserGroup =@UserGroup, kross =@kross, grebenka =@grebenka, modem =@modem, telefon =@telefon, information =@information&#13;&#10;WHERE kod = @kod">
        <SelectParameters>
            <asp:Parameter DefaultValue="0" Name="StatDate" Type="DateTime" />
            <asp:Parameter DefaultValue="0" Name="ApCode" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:QueryStringParameter Name="kod" QueryStringField="kod" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    </asp:Content>
